<?php
/**
 * Created by PhpStorm.
 * User: alei
 * Date: 11/4/2017 AD
 * Time: 16:17
 */
namespace App\Http\Controllers\MobileApi;

use Storage;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Mysql\pre_forum_thread;
use App\Models\Mysql\pre_forum_post;

class ThreadController extends Controller
{
	use GlobalData;
    private $url="http://47.94.110.155:8081/";
	const ROUTE_PREFIX = '/api/*';

	protected $request;

	protected static $forumNameMapFID;

	protected $curTime;



	/**
	 * 创建新的home控制器实例
	 * @param \Illuminate\Http\Request $request
	 */
	public function __construct(Request $request)
	{
		$this->request = $request;
		$this->error = [];
		$this->curTime = time();

		self::$forumNameMapFID = $this->getForumNameMapFID();

		if(config('app.debug')) {
			error_reporting(E_ALL | E_STRICT);
		}
	}

    public function  GetThreadFirstPost()
    {
        $p = $_REQUEST;
        $param['tid']=isset($p['tid']) ?  (int)$p['tid'] : '';
        if( empty($param) )
        {
            $data = array(
                'code' => 5,
                'msg' => '参数不全',
            );
            exit(json_encode($data));
        }
		
		$r=pre_forum_thread::getThreadInfo($param['tid']);
		if( empty($r) ){
			return(json_encode(array('code' => 6,'msg' => 'tid为'.$param['tid'].'的主题不存在','result' => [])));
		} 
        $data['subject'] = $r[0]->subject;
		$data['authorName'] = $r[0]->author;
		$data['authorId'] = $r[0]->authorid;
		$data['publishTime'] = $r[0]->dateline;
		$data['viewCount'] = $r[0]->views;
		$data['replyCount'] = $r[0]->replies;
		$data['authorAvatarUrl']=avatarUrl($r[0]->authorid);
		
		$param['field']='pid,message';
        $r=pre_forum_post:: fetch_first($param);
		
		$data['pid']=$r->pid;
		$tmp_message = $r->message;
		$tmp_message = discuzcode($tmp_message,1,0);
		$data['body']=$tmp_message;
        $data = array(
            'code' => 200,
            'msg' => '主题首帖数据返回成功',
            'result' => $data,
        );
        exit(json_encode($data));
    }







}

